﻿#include "SEABeamWapper.h"
#include "FITK_Kernel/FITKAppFramework/FITKMessage.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsPhysics.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsMaterial.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsShellPhysicsProp.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsNCT.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsSpectraManager.h"
#include "OperatorsInterface/GraphEventOperator.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
SEABeam* SEABeamWapper::new_SEABeam()
{
    SEABeam* beam = new SEABeam;
    this->initShell(beam);
    return beam;
}

void SEABeamWapper::delete_SEABeam(SEABeam * obj)
{
    if (obj) delete obj;
    //渲染层显示数据
    EventOper::GraphEventOperator* graphOper = FITKOPERREPO->getOperatorT<EventOper::GraphEventOperator>("GraphPreprocess");
    if (graphOper == nullptr)return;
    graphOper->updateSEASubSystems();
}

SEABeam * SEABeamWapper::static_SEABeam_GetSEABeam(const QString & name)
{
    SEABeam* beam = new SEABeam(name);
    this->initShell(beam);
    return beam;
}

void SEABeamWapper::addPoint(SEABeam * obj, int pointId)
{
    if (!obj)return;
    bool ok = obj->addPoint(pointId);
    if (!ok) {
        AppFrame::FITKMessageError("Add point failed !");
    }
}

void SEABeamWapper::createBeam(SEABeam * obj)
{
    if (!obj)return;
    bool ok = obj->createBeam();
    if (!ok) {
        AppFrame::FITKMessageError("Creat Beam failed !");
    }
    else
    {
        //渲染层显示数据
        EventOper::GraphEventOperator* graphOper = FITKOPERREPO->getOperatorT<EventOper::GraphEventOperator>("GraphPreprocess");
        if (graphOper == nullptr)return;
        int objID = obj->getBeamID();
        graphOper->updateGraph(objID, true);

    }
}

QString SEABeamWapper::getName(SEABeam * obj)
{
    if (obj)
        return obj->getName();
    return QString();
}

void SEABeamWapper::setName(SEABeam * obj, const QString & name)
{
    if (!obj)return;
    bool ok = obj->setName(name);
    if (!ok) {
        AppFrame::FITKMessageError("Set Name failed !");
    }
}

void SEABeamWapper::setPhysicalProp(SEABeam * obj, const QString & pro)
{
    if (!obj)return;
    bool ok = obj->setPhysicalProp(pro);
    if (!ok) {
        AppFrame::FITKMessageError("Set Physical Property failed !");
    }
}

void SEABeamWapper::setDamping(SEABeam * obj, int type, const QString & damping)
{
    if (!obj)return;
    bool ok = obj->setDamping(type, damping);
    if (!ok) {
        AppFrame::FITKMessageError("Set Damping failed !");
    }
}

void SEABeamWapper::setSEAMatrixSolution_ModalDensity(SEABeam * obj, int type, bool isSolution, bool isModalDensity, const QString & modalDensity)
{
    if (!obj)return;
    bool ok = obj->setSEAMatrixSolution(type, isSolution);
    if (!ok) {
        AppFrame::FITKMessageError("Set SEA Matrix Solution failed !");
        return;
    }
    ok = obj->setModalDensity(type, isModalDensity, modalDensity);
    if (!ok) {
        AppFrame::FITKMessageError("Set Modal Density failed !");
    }
}

QString SEABeamWapper::getGeometryProp(SEABeam * obj)
{
    if (obj)  return obj->getGeometryProp();
    return QString();
}

void SEABeamWapper::initShell(SEABeam * beam)
{
    if (beam == nullptr) return;
    Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
    if (phy == nullptr) return;

    Acoustics::FITKAcousticsMaterialManager* matMgr = phy->getMaterialManager();
    Acoustics::FITKAcousticsSpectraManager* specMgr = phy->getFITKAcousticsSpectraManager();
    Acoustics::FITKAcousticsNCTManager* nctMgr = phy->getFITKAcousticsNCTManager();
    Acoustics::FITKAcousticsPhysicsPropManager* propMgr = phy->getPhysicsPropManager();

    beam->setMaterialManager(matMgr);
    beam->setSpectraMgr(specMgr);
    beam->setNCTMgr(nctMgr);
    beam->setPropertyManager(propMgr);

}

SEABeam::SEABeam(const QString& name) :
    Acoustics::PyFITKSEABeam(name)
{

}
SEABeam::SEABeam() :
    Acoustics::PyFITKSEABeam()
{

}
